/**
 * N个选手，已知当前积分，还有若干场比赛
 * 问1号选手最好的排名。
 * 注意到N和M都不大，暴力深搜
 */
#include <bits/stdc++.h>
using namespace std;

#include <bits/extc++.h>
using namespace __gnu_pbds;


using llt = long long;
using Real = double;
using vi = vector<int>;
using pii = pair<int, int>;

int N, M;
vi A;
vector<pii> Game;
int Ans;

int f(vi a){
    int level = a[1];
    sort(a.begin(), a.end(), greater<int>());
    int k = 1, pre = 0;
    for(auto i : a){
        if(i == level) return k;

        k += 1;
    }
    assert(0);
    return 0;
}

void dfs(int depth){
    if(depth == M){
        Ans = min(Ans, f(A));
        return;
    }

    int u = Game[depth].first;
    int v = Game[depth].second;

    A[u] += 3;
    dfs(depth + 1);
    A[u] -= 3;

    A[u] += 1, A[v] += 1;
    dfs(depth + 1);
    A[u] -= 1, A[v] -= 1;

    A[v] += 3;
    dfs(depth + 1);
    A[v] -= 3;

    return;
}

int proc(){
    Ans = N + N;
    dfs(0);
    return Ans;
}

int main(){
#ifndef ONLINE_JUDGE
    freopen("z.txt", "r", stdin);
#endif
    ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(0);
    int nofkase = 1;
    cin >> nofkase;
    while(nofkase--){
        cin >> N >> M;
        A.assign(N + 1, {});
        for(int i=1;i<=N;++i) cin >> A[i];
        Game.assign(M, {});
        for(auto & p : Game) cin >> p.first >> p.second;
        cout << proc() << "\n";
    }
    return 0;
}